/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.mycompany.ingsoc2;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author sfreiman
 */
public class VcLstLogin implements ActionListener {

    private VcLoginView myLoginView;
    private VcLoginModel myLoginModel;
    private VcPrincipalController principalControler;

    public VcLstLogin(VcLoginView LV, VcLoginModel LM,VcPrincipalController MC) {
        this.myLoginView = LV;
        this.myLoginModel = LM;
        this.principalControler=MC;
    }

    public void actionPerformed(ActionEvent e) {
        String txtNombre;
        String txtPassword;

        txtNombre = this.myLoginView.getTxtUsuario();
        txtPassword = this.myLoginView.getTxtPassword();
        if (myLoginModel.validar(txtNombre, txtPassword)) {
            try {
                this.myLoginView.mostrarResultado("valido");
                principalControler.mostrarPantalla();//llamar a el controlador de principal, y ahi llamar a mostrar principal.
                
                
                this.myLoginView.cerrar();
            } catch (SQLException ex) {
                Logger.getLogger(VcLstLogin.class.getName()).log(Level.SEVERE, null, ex);
            }
        } else {
            this.myLoginView.mostrarResultado("Usuario o contraseña invalidos");
        }
    }
}
